/**
 * @param {number[]} digits
 * @return {number[]}
 */
var plusOne = function (digits) {
  let ifadd = false
  let i = digits.length - 1
  let num = parseInt(digits[i])
  num++
  let res = num % 10
  digits[i] = res
  if (!res) {
    ifadd = true
    while (i > 0) {
      i--
      if (ifadd) {
        let num = parseInt(digits[i])
        num++
        digits[i] = num % 10
        ifadd = !digits[i] % 10
      }
    }
  }
  if (digits[0] === 0) {
    digits.unshift('1')
  }
  return digits
}
console.log(plusOne([6, 1, 4, 5, 3, 9, 0, 1, 9, 5, 1, 8, 6, 7, 0, 5, 5, 4, 3]))
